#include "HBSD.h"
#include <list>
#include <string>
#include "Console_Logging.h"
#include <iostream>

using namespace std;


int main(int argc, const char** argv) 
{
	list<string> args;

	for(int i = 0; i<argc; i++)
	{	
		if(i == 0)
			continue;
		args.push_back(argv[i]);
	}
	HBSD::InitStaticMembers();
	// Get options.
	HBSD::parseOpts(args);
	
	// Get values from the configuration file.
	HBSD::loadConfig();
	
	// Initialize logging to use during execution. Only set
	// the logging level if specified in the command line or HBSD
	// configuration file, otherwise we are content with what the
	// logging system defaults to.
	try 
	{
		HBSD::log = (Logging*) new Console_Logging();
		if (HBSD::logConfiguration.empty()) 
		{
			HBSD::log->conf();
		} else 
		{
			HBSD::log->conf(HBSD::logConfiguration);
		}
		if (HBSD::logLevelOpt) 
		{
			HBSD::log->setLevel(HBSD::logLevel);
		} else 
		{
			HBSD::logLevel = HBSD::log->getLevel();
		}
	} 
	catch (exception &e) 
	{
		cerr<< "Unable to instantiate or initialize logging: "<< e.what()<<endl;
		exit(1);
	}
	
	// Set up our SAX XML handler.
	HBSD::setupSAX();
	
	// Set up multicast socket that we'll be receiving messages
	// from the DTN daemon on.
	HBSD::setupMulticast();
	
	// We are now initialized and ready to begin routing. Start the main
	// thread.
	HBSD* mainRouter = new HBSD(HBSD::THRD_ROUTERLOOP);
	
}
